package org.mspring.mlog.dao.impl;

import org.mspring.mlog.dao.JobLogDao;
import org.mspring.mlog.entity.JobLog;
import org.mspring.platform.dao.hibernate.GenericDao;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Gao Youbo
 * @since 2014-01-11
 */
@Repository
public class JobLogDaoImpl extends GenericDao<JobLog, Long> implements JobLogDao {

    @Override
    public JobLog findLastestExecute(long jobId) {
        return uniqueResult("select jobLog from JobLog jobLog where jobLog.job.id = ? and jobLog.success = true order by jobLog.time desc", jobId);
    }

    @Override
    public void clearBeforeTime(String date) {
        super.executeUpdate("delete JobLog jobLog where jobLog.time < ?", date);
    }

    @Override
    public void clear() {
        super.executeUpdate("delete JobLog jobLog");
    }
}
